﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace ATM_Pro.Log
{
    public class Log : log4net.ILog
    { 

        private Log()
        {

        }

        private static log4net.ILog log = log4net.LogManager.GetLogger("MyLog");
        public static log4net.ILog GetInstance()
        {
            return log;
        }
        #region ILog Members

        public void Debug(object message, Exception exception)
        {
            log.Debug(message, exception);  
        }

        public void Debug(object message)
        {
            log.Debug(message);
        }

        public void DebugFormat(IFormatProvider provider, string format, params object[] args)
        {
            log.DebugFormat(provider, format, args);
        }

        public void DebugFormat(string format, object arg0, object arg1, object arg2)
        {
            log.DebugFormat(format,arg0,arg1,arg2);
        }

        public void DebugFormat(string format, object arg0, object arg1)
        {
            log.DebugFormat(format,arg0,arg1);
        }

        public void DebugFormat(string format, object arg0)
        {
            log.DebugFormat(format, arg0);
        }

        public void DebugFormat(string format, params object[] args)
        {
            log.DebugFormat(format, args);
        }

        public void Error(object message, Exception exception)
        {
            log.Error(message, exception);
        }

        public void Error(object message)
        {
            log.Error(message);
        }

        public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
        {
            log.ErrorFormat(provider, format, args);
        }

        public void ErrorFormat(string format, object arg0, object arg1, object arg2)
        {
            log.ErrorFormat(format, arg0, arg1, arg2);
        }

        public void ErrorFormat(string format, object arg0, object arg1)
        {
            log.ErrorFormat(format, arg0,arg1);
        }

        public void ErrorFormat(string format, object arg0)
        {
            log.ErrorFormat(format, arg0);
        }

        public void ErrorFormat(string format, params object[] args)
        {
            log.ErrorFormat( format, args);
        }

        public void Fatal(object message, Exception exception)
        {
            log.Fatal(message, exception);
        }

        public void Fatal(object message)
        {
            log.Fatal(message);
        }

        public void FatalFormat(IFormatProvider provider, string format, params object[] args)
        {
            log.FatalFormat(provider, format, args);
        }

        public void FatalFormat(string format, object arg0, object arg1, object arg2)
        {
            log.FatalFormat(format, arg0,arg1,arg2);
        }

        public void FatalFormat(string format, object arg0, object arg1)
        {
            log.FatalFormat( format, arg0,arg1);
        }

        public void FatalFormat(string format, object arg0)
        {
            log.FatalFormat( format, arg0);
        }

        public void FatalFormat(string format, params object[] args)
        {
            log.FatalFormat( format, args);
        }

        public void Info(object message, Exception exception)
        {
            log.Info(message, exception);
        }

        public void Info(object message)
        {
            log.Info(message);
        }

        public void InfoFormat(IFormatProvider provider, string format, params object[] args)
        {
            log.InfoFormat(provider, format, args);
        }

        public void InfoFormat(string format, object arg0, object arg1, object arg2)
        {
            log.InfoFormat(format, arg0, arg1, arg2);
        }

        public void InfoFormat(string format, object arg0, object arg1)
        {
            log.InfoFormat(format, arg0, arg1);
        }

        public void InfoFormat(string format, object arg0)
        {
            log.InfoFormat(format, arg0);
        }

        public void InfoFormat(string format, params object[] args)
        {
            log.InfoFormat(format, args);
        }

        public bool IsDebugEnabled
        {
            get { return log.IsDebugEnabled; }
        }

        public bool IsErrorEnabled
        {
            get { return log.IsErrorEnabled; }
        }

        public bool IsFatalEnabled
        {
            get { return log.IsFatalEnabled; }
        }

        public bool IsInfoEnabled
        {
            get { return log.IsInfoEnabled; }
        }

        public bool IsWarnEnabled
        {
            get { return log.IsWarnEnabled; }
        }

        public void Warn(object message, Exception exception)
        {
            log.Warn(message, exception);
        }

        public void Warn(object message)
        {
            log.Warn(message);
        }

        public void WarnFormat(IFormatProvider provider, string format, params object[] args)
        {
            log.WarnFormat(provider, format, args);
        }

        public void WarnFormat(string format, object arg0, object arg1, object arg2)
        {
            log.WarnFormat(format, arg0, arg1, arg2);
        }

        public void WarnFormat(string format, object arg0, object arg1)
        {
            log.WarnFormat(format, arg0, arg1);
        }

        public void WarnFormat(string format, object arg0)
        {
            log.WarnFormat(format, arg0);
        }

        public void WarnFormat(string format, params object[] args)
        {
            log.WarnFormat(format, args);
        }

        #endregion

        #region ILoggerWrapper Members

        public log4net.Core.ILogger Logger
        {
            get { return log.Logger; }
        }

        #endregion


        #region
        ////出错之后计入日志文件
        //public void ObjectDisposedException(ObjectDisposedException e2)
        //{
        //    //如果是同一天的话，则打开文件在末尾写入。如果不是同一天，则创建文件写入文件
        //    //判断是否存在文件

        //    string fileName = GenericLogFileToday();
        //    //如果存在文件，则向文件添加日志
        //    StreamWriter sw = new StreamWriter(fileName, true);
        //    sw.WriteLine("============================================================================");
        //    sw.WriteLine(GenericLogTime());
        //    sw.WriteLine(e2.Message);
        //    sw.Close();
        //    sw.Dispose();
        //}

        ////写入当前连接信息
        //public void WriteConnectInfo(string user,string ip,string address,string state)
        //{
        //    //如果是同一天的话，则打开文件在末尾写入。如果不是同一天，则创建文件写入文件
        //    //判断是否存在文件

        //    string fileName = GenericLogFileToday();
        //    //如果存在文件，则向文件添加日志
        //    StreamWriter sw = new StreamWriter(fileName, true);
        //    sw.WriteLine("============================================================================");
        //    sw.WriteLine(GenericLogTime());
        //    sw.WriteLine("用户：" + user + " 连接IP：" + ip + " ATM地址：" + address + " 连接状态：" + state);
        //    sw.Close();
        //    sw.Dispose();
        //   //Monitor.Exit(obj);
        //}

        //private string GenericLogFileToday()
        //{
        //    string fileName = GenericLogFileName();
        //    if (!File.Exists(fileName))
        //        File.Create(fileName);
        //    return fileName;
        //}

        //private string GenericLogFileName()
        //{
        //    return DateTime.Today.ToString("yyyyMMdd")+".log";
        //}

        //private string GenericLogTime()
        //{
        //    return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":";
        //}
        #endregion
    }
}
